#include "include.h"

//AUX立体声通路配置

static sdadc_cfg_t spk_cfg;

extern volatile bool sdadc_w4_kick;

AT(.text.mic)
void spk_audio_output_callback_set(audio_callback_t callback)
{
    spk_cfg.callback = (pcm_callback_t)callback;

    //改到蓝牙连接后再初始化，节省未连接功耗
//    sdadc_init(&spk_cfg);
//    sdadc_start(spk_cfg.channel);
}

AT(.text.mic)
void spk_init(u8 sample_rate, u16 samples)
{
    memset(&spk_cfg, 0, sizeof(sdadc_cfg_t));

    spk_cfg.sample_rate = sample_rate;
    spk_cfg.samples     = samples*2;
    spk_cfg.out_ctrl    = ADC2DAC_EN;

    aux_channel_get_param((uint16_t *)&spk_cfg.channel, &spk_cfg.gain);

    //这里先注释掉，在callback_set中设置callback函数后再初始化
//    sdadc_init(&spk_cfg);
//    sdadc_start(spk_cfg.channel);
}

void spk_start(void)
{
    sdadc_init(&spk_cfg);
    sdadc_start(spk_cfg.channel);

    sdadc_w4_kick = true;
}

AT(.com_text.spk.kick)
void wireless_spk_kick(void)
{
    if (sdadc_w4_kick) {
        sdadc_w4_kick = false;
        sdadc_start_kick(spk_cfg.channel);
    }
}

void spk_stop(void)
{
    sdadc_exit(spk_cfg.channel);
}

